
import java.awt.Color;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Dorothy
 */
public class SearchEmployee extends javax.swing.JFrame {

    
    /**
     * declaring and instantiating variables to connect to database
     */
      
    Connection conn = null;
        PreparedStatement p = null;
        ResultSet rs = null;
        
        String[] colname = {"eId", "eName", "email", "password"};
        String [] searchOptions = {"eId", "eName", "email", "password"};
        DefaultTableModel dm = new DefaultTableModel(colname, 4); 
      
    /**
     * Creates new form SearchEmployee
     */
    public SearchEmployee(){
        initComponents();
        setVisible(true);
        getContentPane().setBackground(Color.BLACK);
        employeeTable.setEnabled(false);
        employeeTable.setModel(dm);
        dm.setColumnIdentifiers(colname);
        
        
        
        for(int i=0; i<searchOptions.length;i++){       //add items to combobox
           searchCombo.addItem(searchOptions[i]);       
        }
        
        System.out.println("SQL Test");

        try {
            
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/comfort_hub?user=root&password=root");
        } catch (Exception e) {
            System.out.println(e);
            System.exit(0);
        }

        System.out.println("Connection established");   
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")

   
    /**
     * @return CLOSEButton,SearchButtonEmployee,SearchEmployeeText,searchCombo
     * msgLabel,employeeTable,dm
     */
    
     public JButton getCLOSEButton(){
       return  CLOSEButton;
    }
      
      
       public JButton getSEARCHButton(){
       return  SearchButtonEmployee;
    }
    
    
      public JTextField getSearchEmployeeText(){
       return  SearchEmployeeText;
    } 
    

public JComboBox getsearchCombo(){
       return  searchCombo;
    }

public JLabel getmsgLabel(){
       return  msgLabel;
    }



public JTable getemployeeTable(){
       return  employeeTable;
    }



public DefaultTableModel getModel(){
return dm;
}

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        msgLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        CLOSEButton = new javax.swing.JButton();
        searchCombo = new javax.swing.JComboBox();
        SearchEmployeeText = new javax.swing.JTextField();
        SearchButtonEmployee = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        employeeTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        msgLabel.setBackground(new java.awt.Color(255, 255, 255));

        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("EMPLOYEE");

        CLOSEButton.setBackground(new java.awt.Color(153, 102, 0));
        CLOSEButton.setForeground(new java.awt.Color(102, 0, 51));
        CLOSEButton.setText("CLOSE");
        CLOSEButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CLOSEButtonActionPerformed(evt);
            }
        });

        searchCombo.setBackground(new java.awt.Color(153, 102, 0));
        searchCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchComboActionPerformed(evt);
            }
        });

        SearchEmployeeText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchEmployeeTextActionPerformed(evt);
            }
        });

        SearchButtonEmployee.setBackground(new java.awt.Color(153, 102, 0));
        SearchButtonEmployee.setForeground(new java.awt.Color(102, 0, 102));
        SearchButtonEmployee.setText("SEARCH");
        SearchButtonEmployee.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchButtonEmployeeActionPerformed(evt);
            }
        });

        employeeTable.setBackground(new java.awt.Color(153, 102, 0));
        employeeTable.setModel(dm);
        jScrollPane1.setViewportView(employeeTable);

        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Dorothy\\Documents\\NetBeansProjects\\comfort-hub\\s4.jpg")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(54, Short.MAX_VALUE)
                .addComponent(msgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 464, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(74, 74, 74))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(222, 222, 222)
                        .addComponent(CLOSEButton, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 508, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jLabel2)
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(searchCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(SearchEmployeeText, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(SearchButtonEmployee, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel1))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(searchCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SearchEmployeeText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SearchButtonEmployee)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addComponent(msgLabel)
                .addGap(73, 73, 73)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63)
                .addComponent(CLOSEButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CLOSEButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CLOSEButtonActionPerformed
        // TODO add your handling code here:
        //this.dispose();
    }//GEN-LAST:event_CLOSEButtonActionPerformed

    private void searchComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchComboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchComboActionPerformed

    private void SearchEmployeeTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchEmployeeTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SearchEmployeeTextActionPerformed

    private void SearchButtonEmployeeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchButtonEmployeeActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_SearchButtonEmployeeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SearchEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SearchEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SearchEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SearchEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SearchEmployee().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CLOSEButton;
    private javax.swing.JButton SearchButtonEmployee;
    private javax.swing.JTextField SearchEmployeeText;
    private javax.swing.JTable employeeTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel msgLabel;
    private javax.swing.JComboBox searchCombo;
    // End of variables declaration//GEN-END:variables
}
